package com.example.wechat_scan

import android.content.Intent
import android.util.Log
import com.king.camera.scan.AnalyzeResult
import com.king.camera.scan.CameraScan
import com.king.camera.scan.analyze.Analyzer
import com.king.wechat.qrcode.scanning.WeChatCameraScanActivity
import com.king.wechat.qrcode.scanning.analyze.WeChatScanningAnalyzer

class WeChatQRCodeActivity : WeChatCameraScanActivity() {

    override fun onScanResultCallback(result: AnalyzeResult<List<String>>) {
        cameraScan.setAnalyzeImage(false)
        Log.d(TAG, result.result.toString())

        if (result.result.isNotEmpty()) {
            val intent = Intent().apply {
                putExtra(CameraScan.SCAN_RESULT, result.result.toTypedArray())
            }
            setResult(RESULT_OK, intent)
            finish()
        }
    }

    override fun createAnalyzer(): Analyzer<MutableList<String>> {
        return WeChatScanningAnalyzer()
    }

    companion object {
        const val TAG = "WeChatQRCodeActivity"
    }
}